package cn.wolfcode.cmis.dao.lmpl;

import cn.wolfcode.cmis.dao.IEmployeeDAO;
import cn.wolfcode.cmis.domain.Employee;
import cn.wolfcode.cmis.qo.QueryObject;
import cn.wolfcode.cmis.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class EmployeeDAOImpl implements IEmployeeDAO {
    @Override
    public void insert(Employee emp) {
        SqlSession session = MyBatisUtil.openSqlSession();
        session.insert("cn.wolfcode.cmis.mapper.EmployeeMapper.insert", emp);
        session.close();
    }

    @Override
    public void update(Employee emp) {
        SqlSession session = MyBatisUtil.openSqlSession();
        session.update("cn.wolfcode.cmis.mapper.EmployeeMapper.update", emp);
        session.close();

    }

    @Override
    public void delete(Long id) {
        SqlSession session = MyBatisUtil.openSqlSession();
        session.delete("cn.wolfcode.cmis.mapper.EmployeeMapper.delete", id);
        session.close();
    }

    @Override
    public Employee selectOne(Long id) {
        SqlSession session = MyBatisUtil.openSqlSession();
        Employee emp = session.selectOne("cn.wolfcode.cmis.mapper.EmployeeMapper.selectOne", id);
        return emp;
    }

    @Override
    public List<Employee> selectList() {
        SqlSession session = MyBatisUtil.openSqlSession();
        List<Employee> list = session.selectList("cn.wolfcode.cmis.mapper.EmployeeMapper.selectList");
        return list;
    }

    @Override
    public int queryForCount(QueryObject qo) {
        SqlSession session = MyBatisUtil.openSqlSession();
        int count = session.selectOne("cn.wolfcode.cmis.mapper.EmployeeMapper.queryForCount", qo);
        session.close();
        return count;
    }

    @Override
    public List<Employee> queryForList(QueryObject qo) {
        SqlSession session = MyBatisUtil.openSqlSession();
        List<Employee> list = session.selectList("cn.wolfcode.cmis.mapper.EmployeeMapper.queryForList", qo);
        session.close();
        return list;
    }


}
